package com.lianxi.mongodb;

import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Filters;
import org.bson.Document;
import org.junit.Test;

import javax.annotation.Resource;

public class MyMongodb {



    @Test
    public void test(){
        MongoClient mongoClient=new MongoClient("127.0.0.1",27017);
        MongoDatabase test2 = mongoClient.getDatabase("test2");
        MongoCollection<Document> c1 = test2.getCollection("c1");
        long count = c1.count();

        //查找age为1的文档
        FindIterable<Document> d1 = c1.find(Filters.eq("age", 1));
        for (Document document : d1) {
            System.out.println(document);
        }


//        FindIterable<Document> documents = c1.find();
//        for (Document document : documents) {
//            System.out.println(document);
//
//        }

    }
}
